home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
compuserve-file-archive
/
05 Programming
/
CPFUNC.DOC
< prev
next >
Wrap
Text File
|
2019-04-13
|
20KB
|
951 lines
CPowerC Functions
-----------------
--------------------------------------
abs, fabs - absolute value
abs(i)
int i;
fabs(f)
float f;
abs and fabs return the absolute value
of their arguments
--------------------------------------
atoi, atof - convert strings to numbers
atoi(iptr)
char *iptr;
float atof(fptr)
char *fptr;
atoi converts the string pointed to by
its argument into an integer
atof converts the string pointed to by
its argument into a float quantity
both functions ignore leading spaces
---------------------------------------
bcmp, bcopy, bzero, ffs - bit and byte
string functions
bcmp(p1, p2, len)
char *p1, *p2;
bcopy(p1, p2, len)
char *p1, *p2;
ffs(i)
int i;
bcmp compares len bytes of the strings
p1 and p2 and returns zero if they are
the same, none-zero otherwise
bcopy copies len bytes from string p1
to string p2
bzero fills string p with len zeros
ffs returns the position of the first
set bit in its argument. bits are
numbered starting at one. if the
argument is zero ffs returns -1
--------------------------------------
exit, abort - terminate execution
exit()
abort()
exit and abort end program execution.
all files opened by fopen are closed
--------------------------------------
exp, log, log10, pow, sqrt - assorted
math functions
#include <math.h>
float exp(x)
float x;
float log(x)
float x;
float log10(x)
float x;
float pow(x, y)
float x, y;
float sqrt(x)
float x;
exp returns e**x
log returns the natural logarithm of x
log10 returns base 10 logarithm of x
pow returns x**y.
sqrt returns the square root of x
--------------------------------------
ferror - check for error
feof - check for end of file
#include <stdio.h>
ferror()
feof(stream)
FILE stream;
ferror returns non-zero if an error
occurred during the last disk
operation, zero otherwise
feof returns non-zero if the specified
stream has reached end of file, zero
otherwise
--------------------------------------
floor, ceil, modf - get integer part
of float
#include <math.h>
float floor(x)
float x;
float ceil(x)
float x;
float modf(x,ptr)
float x, *ptr;
floor returns the greatest integer not
greater than x
ceil returns the least integer not
less than x
modf returns the positive fractional
part of x and stores the integer part
indirectly through ptr
--------------------------------------
fopen, freopen, fclose - open disk
file for i/o
#include <stdio.h>
FILE fopen(filename,mode)
char *filename,*mode;
FILE freopen(filename,mode,stream)
char *filename,*mode;
FILE stream;
fclose(stream)
FILE stream;
fopen opens a disk file file for
reading or writing. the string
filename contains the name of the file
and the first character of the string
mode specifies read or write ('r' or
'w'). the default file type is
sequential, but program file types may
selected. fopen returns a file number
(hearafter referred to as a stream)
which may be used in later i/o, or it
returns zero if the file cannot be
opened
freopen opens a file much the same as
fopen does. the file stream is first
closed, then if successful the old
stream is assigned to the new file.
this is useful to assign the constant
streams stdin and stdout to disk
files
ferror should be checked after every
fopen
fclose closes the specified file
--------------------------------------
fread, fwrite - array input/output
#include <stdio.h>
fread(ptr,elsize,nelem,stream)
char *ptr;
FILE stream;
fwrite(ptr,elsize,nelem,stream)
char *ptr;
FILE stream;
Fread/fwrite reads/writes an array
containing nelem elements each of size
elesize bytes geginning at ptr from/to
the specified stream
fread returns zero upon end of file
--------------------------------------
frexp,ldexp - split float into
mantissa and exponent
float frexp(value,ptr)
float value;
int *ptr;
float ldexp(value,exp)
float value;
frexp splits value into a mantissa m
of manitude less than 1 (which is
returned) and an exponent exp (which
is stored indirectly through ptr) such
that value = m * 2**exp
ldexp returns value * 2**exp
--------------------------------------
getc,getchar,fgetc,getw
- input character or integer
#include <stdio.h>
int getc(stream)
FILE stream;
int getchar()
int fgetc(stream)
FILE stream;
int getw(stream)
FILE stream;
Getc and fgetc read a character from
the specified stream
Getchar reads a character from the
standard input
Getw reads an integer (two bytes)
from the specified stream
All of these functions return EOF upon
end of file, however, since EOF is a
valid integer, feof should be used to
check for end of file after getw
--------------------------------------
gets, fgets - input a string
#include <stdio.h>
char *gets(s)
char *s;
char *fgets(s,n,stream)
char *s;
FILE stream;
Gets inputs a string from the standard
input. it reads characters into s
until a newline is encountered. the
newline is replaced with a zero
Fgets inputs a string from the
specified stream. it reads n-1
characters or until a newline is
encountered whichever comes first. the
newline is not replaced but a zero is
placed after the last character read
Both functions return s upon normal
completion or NULL upon end of file
--------------------------------------
highmem - memory configuration
highmem(address)
unsigned address;
Highmem sets the highest address that
a C program can use. the run time
stack will not go past this address,
and the memory allocation functions
(malloc, calloc, realloc) will not
allocate memory higher than this
address. the value of the argument
must be one greater than the desired
address. if highmem is not called,
address defaults to 0xd000, which
means the highest address which can be
used is 0xcfff
--------------------------------------
hypot, cabs - calculate hypotenuse
#include <math.h>
float hypot(x,y)
float x, y;
float cabs(c)
struct (* float x,y; *) *c;
Hypot and cabs return sqrt(x*x + y*y)
--------------------------------------
isalpha, ... - classify characters
isalpha(c)
The following functions return
non-zero integers if the stated
condition is true, zero otherwise
isalpha c is a letter
isupper c is an upper case letter
islower c is a lower case letter
isdigit c is a digit
isalnum c is a letter or a digit
isspace c is a space or a newline
ispunct c is a punctuation char
isprint c is a printable char
iscntrl c is a control char
isascii c has value less than 0200
--------------------------------------
malloc, calloc, realloc,free
- memory allocation
char *malloc(size)
unsigned size;
char *calloc(nelem, elsize)
unsigned nelem, elsize;
char *realloc(ptr, size)
char *ptr;
unsigned size;
free(ptr)
char *ptr;
Malloc returns a pointer to a block of
memory containing at least size bytes
Calloc returns a pointer to a block of
zero-filled memory containing at least
nelem * elsize bytes
Realloc copies the block pointed to by
ptr into a new block containing at
least size bytes. ptr must point to a
block allocated by malloc, calloc or
realloc
free releases the block pointed to by
ptr into the free memory list
Malloc, calloc and realloc all return
the null pointer (0) if there is not
enough free memory to satisfy the
request
--------------------------------------
open, close - BASIC style open/close
open(fileno, device, secaddr, name)
char *name;
close(fileno);
The arguments of open correspond
exactly to the file number, device
number, secondary address, and file
name arguments of the BASIC OPEN
command. consult a Commodore 64 manual
for the meanings of the arguments.
similarly, close corresponds to the
BASIC CLOSE command. open returns zero
if the file can't be checked after
opening a write file
The file number argument may be used
any place a stream (ie. a value
returned by fopen) is used. File
numbers 1 through 4 are reserved for
system use. if open and fopen are used
at the same time file numbers passed
to open should be limited to the range
5 through 9
--------------------------------------
opendir, readdir, rewinddir closedir
- directory functions
#include <dir.h>
opendir(unit:)
struct direct *readdir()
rewinddir()
closedir()
Opendir opens a disk directory for
reading. the unit from which the
directory is to be read may be
specified. if the directory can't be
opened NULL is returned. NOTE: the
directory functions do not apply to
the RAMDISK.
Readdir reads the next directory entry
and returns a pointer to it. if there
are no more entries NULL is rteturned.
see the header file dir.h and the
VIC-1541 User's Manual for the format
of a directory entry
Rewinddir causes readdir to read the
first entry upon the next call
Closedir closes the directory.
--------------------------------------
(for Commodore 128)
open2() - BASIC style open to unit#
open2(name, filename, unit, channel)
char *name;
int filenum;
char unit;
int channel;
open2() is the same as open(), except
that the disk drive is specified by a
unit number rather than a device
number. if "filename" is not empty,
then the unit number is taken from
there, otherwise it is taken from
"unit"
--------------------------------------
(for Commodore 128)
peek() - BASIC style peek()
peek(bank, address);
unsigned bank, address;
peek() returns the contents of the
memory location in "bank" at "address"
--------------------------------------
(for Commodore 128)
poke() - BASIC style poke
poke(bank, address, value)
unsigned bank, address, value;
poke() puts the byte "value" into the
memory locatin specified by "bank" and
"address"
--------------------------------------
printf, fprintf, sprintf
- formatted output
#include <stdio.h>
printf(control [, arg] ...)
char *control;
fprintf(stream, control, [, arg] ...)
FILE stream;
char *control;
sprintf(s, control [, arg] ...)
char *s, *control;
These functions output optional lists
of arguments according to a format
specified in the null terminated
control string. printf sends output to
the standard output. fprintf sends
output to the specified stream.
sprintf places output in the string s.
sprintf also places a null character
in s after the last output character.
The control string may contain
ordinary characters, which are output,
and conversion specifiers which
specify how an argument is to be
formatted. each conversion specifier
begins with a percent character (%)
and is followed by:
An optional dash (-) which indicates
left adjustment of the argument in the
output field. right adjustment is the
default
An optional number indicating the
minimum field width. a converted
argument will not be fruncated even if
it won't fit in the specified field.
if the first digit of the field width
is zero the field will be padded with
zeros, otherwise it will be padded
with spaces. the maximum width is 64
characters
An optional period (.) followed by a
number indicates the precision for a
float or string argument. for floats
the precision indicates the number of
digits to be printed after the decimal
point (default is six). if the
precision is explicitly zero no
decimal point is printed. for strings
the precision indicates the maximum
number of characters from the string
to be printed (default is the whole
string)
A letter is placed after the percent
(%) conversion specifier indicating
the type of conversion to performed as
follows:
d - an integer argument is printed as
a possibly signed decimal number
u - an integer argument is printed as
an unsigned decimal number
o - an integer argument is printed as
an octal number
x - an integer argument is printed as
an hexadecimal number
f - a float argument is printed
s - a character pointer argument is
assumed to point to a null terminated
string which is printed
c - an integer argument is assumed to
be a character and is printed as such
For each conversion specifier a
corresponding argument of an
appropriate type must be provided.
To output a percent character use %%.
A star (*) may be used in place of
field width or precision. the value
will be taken from an integer
argument.
--------------------------------------
putc, putchar, fputc, putw
- output a character or integer
#include <stdio.h>
putc(c,stream)
char c;
FILE stream;
putchar(c)
char c;
fputc(c,stream)
char c;
FILE stream;
putw(i, stream)
int i;
FILE stream;
Putc and fputc write a character
to the specified stream. Putchar
writes a character to the standard
output. Puts writes an integer to the
specified stream.
--------------------------------------
puts, fputs - output a string
#include <stdio.h>
puts(s)
char *s;
fputs(s, stream)
char *s;
FILE stream;
Puts writes a NULL-terminated string
to the standard output. Puts outputs
a newline character after the string.
Fputs writes a NULL-terminated string
to the specified stream. Fputs does
not output a newline character.
--------------------------------------
qsort - general purpose sort
qsort(base, nel, elsize, comp)
char *base;
int (*comp)();
Qsort sorts an array beginning at
"base", containing number of elements
"nel", each of size "elsize". "Comp"
is a function pointer to a function
which compares elements. The function
"comp" must take two pointers to
elements of the array and return an
integer less than, equal to, or greater
than zero, as the first element is
less than, equal to, or greater than,
the second.
--------------------------------------
random, srandom
- random number generator
random();
srandom(seed);
Random returns a psuedo-random
integer. Srandom sets the state of
the random number generator. If
srandom is called twice with the same
seed the same sequence of random
numbers is generated.
--------------------------------------
scanf,fscanf,sscanf - formatted output
#include <stdio.h>
scanf(control [, arg] ...)
char *control;
fscanf(stream, control [, arg] ...)
FILE stream;
char *control;
sscanf(s, control [, arg] ...)
char *s, *control;
These functions read sequences of
characters, perform conversions
specified by the control string on
them, and store the converted values
indirectly through pointer arguments.
Scanf reads from the standard input,
fscanf reads from the specified
stream, and sscanf reads from the
string s.
The control string may contain blanks
and newlines, which may match
optional blanks and newlines from the
input, other ordinary characters,
wich must match corresponding
characters from the input, and
conversion specifiers.
Each conversion specifier begins with
a percent character (%) and is
followed by:
An optional star (*) which suppresses
assignment of the converted value.
An optional number which specifies
the maximum field width. Characters
are read up to the first unrecognized
character for the type of conversion
being performed or until the number
of charcters read equals the field
width, whichever comes first. If no
field width is specified characters
are read up to the first unrecognized
character.
A letter following the percent
character indicates the type of
conversion to be performed on the
field as follows:
d - the field is expected to contain
a possibly signed decimal number
which is converted into an integer
x - the field is expected to contain
a hexadecimal number which is
converted into an integer
o - the field is expected to contain
an octal number which is converted
into an integer
f - the field is expected to contain
a possibly signed decimal number with
an optional decimal point and
exponent which is converted into a
float
s - no conversion is performed; the
field is copied into a string
argument with a NULL character
appended
c - the field contains a single
character which is copied into a
character argument
For each conversion specifier (except
for those which suppress assignment)
there must be a corresponding
argument which is a pointer to an
appropriate type. For example, a
coversion requires that there be a
pointer to an integer or an unsigned.
To match a percent character from the
input use %%.
These functions return EOF upon end
of file, otherwise they return the
number of conversions successfully
performed. This number may be less
than the number of conversion
specifiers if, for example,
characters in the control string do
not match corresponding characters
from the input.
To input strings with embedded spaces
use gets or fgets.
--------------------------------------
setjmp, longjmp - long range goto
#include <setjump.h>
setjmp(env)
jmp buf env;
longjmp(env, val)
jmp buf env;
Setjmp stores its stack environment
in "env" and returns zero.
Longjmp restores the stack
environment saved by setjmp and
returns in such a way that it
appears thta the original call to
setjmp has returned with the value
"val".
The calls to setjmp and longjmp may
be in different functions but the
function containing the setjmp call
must not have returned before the
call to longjmp.
--------------------------------------
sin,cos,tan,asin,acos,atan,atan2
- trigonometric functions
#include <math.h>
float sin(x)
float x;
float cos(x)
float x;
float tan(x)
float x;
float asin(x)
float x;
float acos(x)
float x;
float atan(x)
float x;
float atan2(x)
float x;
Sin, cos and tan return the sine,
cosine, and tangent of x
respectively. X is measured in
radians.
Asin, acos and atan return the
arcsine, arccos and arctangent of x
respectively.
Atan2 returns the arctangent of x/y.
--------------------------------------
sinh,cosh,tanh - hyperbolic functions
#include <math.h>
float sinh(x)
float x;
float cosh(x)
float x;
float tanh(x)
float x;
Sinh, cosh and tanh return the
hyperbolic sine, cosine and tangent
of x respectively.
--------------------------------------
strcat,strncat,strcmp,strncmp,strcpy,
strncpy,strlen,index,rindex
- string functions
#include <strings.h>
char *strcat(s1,s2)
char *s1,*s2;
char *strncat(s1,s2,n)
char *s1,*s2;
int n;
strcmp(s1,s2)
char *s1,*s2;
strncmp(s1,s2,n)
char *s1,*s2;
int n;
char *strcpy(s1,s2)
char *s1,*s2;
char *strncpy(s1,s2,n)
char *s1,*s2;
int n;
strlen(s)
char *s;
char *index(s,c)
char *s, c;
char *rindex(s,c)
char *s, c;
All of the following functions
operate on character strings
terminated with zero.
Strcat and strncat concatenate the
strings s1 and s2 and leave the
result in s1. Strncat copies at most
n characters from s2. Both functions
return s1.
Strcmp and strncmp compare the
strings s1 and s2 and return an
integer less than, equal to, or
greater than zero as s1 is lexically
less than, equal to, or greater than
s2. Strncmp compares at most n
characters.
Strcpy and strncpy copies s2 into s1.
Strncpy copies at most n characters.
Both functions return s1.
Strlen returns the number of non-zero
characters in the string s.
Index/rindex returns a pointer to the
leftmost/rightmost occurence of the
character c in the string s. If the
character is not in the string a null
pointer (0) is returned.
--------------------------------------
sys - call machine language subroutine
sys(address, aptr, xptr, yptr)
unsigned address;
char *aptr,*xptr,*yptr;
(for Commodore 128)
sys(bank, address, aptr, xptr, yptr)
int bank;
unsigned address;
char *aptr,*xptr,*yptr;
Sys loads the accumulator, x, and y
registers of the 6510 processor with
the values pointed to by a, x, and y
respectively then jumps to the
subroutine located at the specified
address. Upon completion of the
subroutine the (possibly) new values
contained in the registers are stored
indirectly through the pointer
arguments. Sys returns zero if the
carry flag is clear after the
subroutine call, otherwise it returns
one. This function allows the
programmer to combine assembler and C
code in one program without having to
use a special assembler. Another use
of sys is to access kernal routines
not otherwise supported by the
standard library.
(for Commodore 128)
The "bank" in which the machine code
resides must be specified by a number
from 0 to 15 (See BASIC "BANK"
command).
--------------------------------------